package leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Liangyaoyun
 */
public class leetCode145 {
    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode() {}
        TreeNode(int val) { this.val = val; }
        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
        public List<Integer> postorderTraversal(TreeNode root) {
            //将答案存放在数组中
            List<Integer>res=new ArrayList<>();
            postorder(res,root);
            return  res;
        }
        public void  postorder(List<Integer>res,TreeNode root){
            if (root==null){
                return ;
            }
            postorder(res,root.left);
            postorder(res,root.right);
            res.add(root.val);
        }
}
